package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class DclrVarProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static DclrVarProduction instance = new DclrVarProduction();

    public static DclrVarProduction getInstance() {
        return instance;
    }

   

    /**
     * Regra: dclr_var : tipo_variavel IDENTIFIER array_d*;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (!TipoVariavelProduction.getInstance().analyze(st, et)) {
            return false;
        }
        if (!basicParse(st, TokenClass.IDENTIFIER)) {
            return skipUntilSynchronize(st, et, "Era esperado um tipo. Declaração incompleta.");
        }

        while (ArrayDProduction.getInstance().analyze(st, et)) {
        }

        return true;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.IDENTIFIER);
        first.add(TokenClass.KEYWORD_INTEIRO);
        first.add(TokenClass.KEYWORD_REAL);
        first.add(TokenClass.KEYWORD_LOGICO);
        first.add(TokenClass.KEYWORD_CARACTERE);
        first.add(TokenClass.KEYWORD_STRING);
    }

    @Override
    protected void populateFollow() {
        follow.add(TokenClass.OPERATOR_ASSIGNMENT);
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_SEMICOLON);

        //from declrvarinit.follow
        follow.add(TokenClass.DELIMITER_COMMA);
        follow.add(TokenClass.DELIMITER_SEMICOLON);

        //from args.follow
        follow.add(TokenClass.DELIMITER_CLOSING_PARENTHESIS);
        
    }

}
